package com.kun.serviceutil;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author zhoukun
 * @Date 2021/3/17 21:50
 */
@Configuration
@EnableSwagger2
public class swaggerConfig {
    //是否开启swagger，正式环境一般是需要关闭的，可根据springboot的多环境配置进行设置
    @Value(value = "${swagger.enabled}")
    Boolean swaggerEnabled;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .groupName("webApi")
                // 是否开启
                .enable(swaggerEnabled)
                .select()
                // 扫描的路径包
                //.apis(RequestHandlerSelectors.basePackage("/"))
                // 指定路径处理PathSelectors.any()代表所有的路径
                //.paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("尚医通")
                .description("尚医通接口")
                // 作者信息
                .contact(new Contact("周坤", "https://blog.csdn.net/zk86547462", "86547462@qq.com"))
                .version("1.0.0")
                .build();
    }
}
